package com.wgh;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Updatestudent1
 */
@WebServlet("/Updatestudent1")
public class Updatestudent1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Updatestudent1() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		int id = Integer.valueOf(request.getParameter("id"));
		String interesting = request.getParameter("interesting");
		try {
			      Class.forName("com.mysql.jdbc.Driver");		
					String url = "jdbc:mysql://localhost:3306/jsp";	
					String username = "root";							
					String password = "root";							
					Connection conn = DriverManager.getConnection(url,username,password);
					String sql = "update zhoujianyang set interesting=? where id=?";
					PreparedStatement ps = conn.prepareStatement(sql);
					ps.setString(1,interesting);
					//ps.setString(2,sex);
				
					ps.setInt(2,id);
					ps.executeUpdate();
					ps.close();
					conn.close();
			}catch (Exception e) {
				e.printStackTrace();
			}
			response.sendRedirect("Findstudent");
			

		
		doGet(request, response);
	}

}
